/*
 * @Author: swc shanwenchao12138@163.com
 * @Date: 2024-07-29 15:34:55
 * @LastEditors: swc
 * @LastEditTime: 2024-09-04 11:03:03
 * @FilePath: \xf\src\components\base\graph\c-bpmn\config.ts
 * @Description:
 * @Version: 2.0
 * @Autor: swc
 */
import { T_srv, Tsrv, ifs, ts, tvs, vue } from '@/services';
import {
  N_cFlowchart,
  N_oContextMenu,
  N_oInteraction,
  N_oSimpleToolbar
} from '@/types';
import { I_cmd, T_cmd } from './command';

const cusrNode = (): N_cFlowchart.I_node[] => {
  return [
    {
      name: 'bpmn-begin',
      cls: {
        inherit: 'c-rect',
        attrs: {
          body: {
            rx: 26,
            ry: 26
          },
          label: {
            text: Tsrv.getI18nBySrv('开始')
          }
        },
        data: {
          unique: true
        }
      },
      overwrite: true
    },
    {
      name: 'bpmn-end',
      cls: {
        inherit: 'c-rect',
        attrs: {
          body: {
            rx: 26,
            ry: 26
          },
          label: {
            text: Tsrv.getI18nBySrv('结束')
          }
        },
        data: {
          id: Tsrv.utils.custUUID(8, 16),
          unique: true
        }
      },
      overwrite: true
    },
    {
      name: 'bpmn-activity',
      cls: {
        inherit: 'c-rect',
        markup: [
          {
            tagName: 'rect',
            selector: 'body'
          },
          {
            tagName: 'image',
            selector: 'img'
          },
          {
            tagName: 'text',
            selector: 'label'
          }
        ],
        attrs: {
          body: {
            rx: 6,
            ry: 6
          },
          img: {
            x: 3,
            y: 3,
            width: 12,
            height: 12,
            'xlink:href': 'img/icons/user.png'
          },
          label: {
            text: Tsrv.getI18nBySrv('审批人')
          }
        },
        data: {
          nodeID: Tsrv.utils.custUUID(8, 16),
          checker: {
            value: null,
            label: '空'
          }
        }
      },
      overwrite: true
    },
    {
      name: 'bpmn-gateway',
      cls: {
        inherit: 'c-polygon',
        attrs: {
          body: {
            refPoints: '0,10 10,0 20,10 10,20'
          },
          label: {
            text: '+',
            fontSize: 40
          }
        },
        data: {
          nodeID: Tsrv.utils.custUUID(8, 16),
          condition: {
            value: null,
            label: '空'
          }
        }
      },
      overwrite: true
    }
  ];
};
const cusrEdge = (): N_cFlowchart.I_edge[] => {
  return [
    {
      name: 'bpmn-edge',
      options: {
        inherit: 'edge',
        attrs: {
          line: {
            stroke: '#A2B1C3',
            strokeWidth: 2,
            targetMarker: {
              name: 'block',
              width: 12,
              height: 8
            }
          }
        },
        zIndex: 0
      },
      overwrite: true
    }
  ];
};
const cellContentMenuItem = (): N_oContextMenu.I_menuItem[] => [
  // {
  //   name: 'debug:debug',
  //   title: '测试',
  //   icon: 'wy-icon wy-debug',
  //   isShow: true,
  //   disabled: false,
  //   children: []
  // },
  {
    name: 'copyAdd:cell',
    title: '复制新增',
    icon: 'wy-icon wy-conflictAnalysis',
    isShow: true,
    disabled: false,
    children: []
  },
  {
    name: 'modify:cell:data',
    title: '修改属性',
    icon: 'wy-icon wy-lianluodan',
    isShow: true,
    disabled: false,
    children: []
  }
];
const nodeContentMenuItem = (): N_oContextMenu.I_menuItem[] => [
  {
    name: 'add:node:bpmn-activity',
    title: '新增审批人',
    icon: 'wy-icon wy-renliziyuanguanli',
    isShow: true,
    disabled: false,
    children: []
  },
  {
    name: 'add:node:route',
    title: '新增路由',
    icon: 'wy-icon wy-gongzuoliuchengtu',
    isShow: true,
    disabled: false,
    children: []
  }
];
const blankContentMenuItem = (): N_oContextMenu.I_menuItem[] => [
  {
    name: 'export:blank:svg',
    title: '导出SVG',
    icon: 'wy-icon wy-shuxing',
    isShow: true,
    disabled: false,
    children: []
  },
  {
    name: 'export:blank:png',
    title: '导出PNG',
    icon: 'wy-icon wy-shuxing',
    isShow: true,
    disabled: false,
    children: []
  },
  {
    name: 'export:blank:jpeg',
    title: '导出JPEG',
    icon: 'wy-icon wy-shuxing',
    isShow: true,
    disabled: false,
    children: []
  }
];
const edgeContentMenuItem = (): N_oContextMenu.I_menuItem[] => [];
const graphToolbar: Array<N_oSimpleToolbar.I_Conf> = [
  {
    key: 'c-audit',
    // button |comp
    type: 'button',
    // 图样式 icon名 type==='button' 有效
    class: 'wy-shenhe',
    // 标题，支持国际化
    title: '审核',
    // 按下的样式 单锁开关按扭样式控制 type==='button' 有效
    isOpen: false,
    // 可用状态
    disabled: true,
    // 下级分格线
    separator: false,
    // 是否隐藏
    isHide: false
  }
  // {
  //   key: 'c-unaudit',
  //   // button |comp
  //   type: 'button',
  //   // 图样式 icon名 type==='button' 有效
  //   class: 'wy-fanshenhe1',
  //   // 标题，支持国际化
  //   title: '取消审核',
  //   // 按下的样式 单锁开关按扭样式控制 type==='button' 有效
  //   isOpen: false,
  //   // 可用状态
  //   disabled: true,
  //   // 下级分格线
  //   separator: false,
  //   // 是否隐藏
  //   isHide: false
  // }
];
const saveDetFields = (): Array<N_oInteraction.I_field> => [
  {
    fieldID: '408517182201266176',
    field: 'ver_num',
    type: 'decimal(10,4)',
    isShow: true,
    notNull: true,
    defValue: '',
    comment: '',
    selectionID: null,
    disabled: true,
    defaultFilter: false,
    nodeData: false,
    footerMethod: null,
    formatter: { type: '', decimal: 0, thousandmark: false, currency: '' },
    actions: [],
    auxProp: '',
    minWidth: '',
    appWeight: '',
    isDes: false,
    many2one: {
      toTable: '',
      toField: '',
      isDropdown: false,
      customSearch: '',
      multiConnect: '',
      fields: []
    },
    align: 'left',
    subQuery: ''
  },
  {
    fieldID: '222301287968935937',
    field: 'title',
    type: 'varchar(45)',
    isShow: true,
    notNull: false,
    defValue: '',
    comment: '',
    selectionID: null,
    disabled: false,
    defaultFilter: false,
    nodeData: false,
    footerMethod: null,
    formatter: {
      type: 'i18n',
      decimal: 0,
      thousandmark: false,
      currency: ''
    },
    actions: [],
    auxProp: '',
    minWidth: '',
    appWeight: '',
    isDes: false,
    many2one: {
      toTable: '',
      toField: '',
      isDropdown: false,
      customSearch: '',
      multiConnect: '',
      fields: []
    },
    align: 'left'
  },
  {
    fieldID: '368213481553395712',
    field: 'f_code',
    type: 'varchar(80)',
    isShow: true,
    notNull: false,
    defValue: '',
    comment: '',
    selectionID: null,
    disabled: false,
    defaultFilter: false,
    nodeData: false,
    footerMethod: null,
    formatter: {
      decimal: 0,
      thousandmark: false,
      currency: ''
    },
    actions: [],
    auxProp: '',
    minWidth: '',
    appWeight: '',
    isDes: false,
    many2one: {
      toTable: '',
      toField: '',
      isDropdown: false,
      customSearch: '',
      multiConnect: '',
      fields: []
    },
    align: 'left'
  },

  {
    fieldID: '222301287968935936',
    field: '_sys_fun_id',
    type: 'bigint(20)',
    isShow: true,
    notNull: false,
    defValue: '',
    comment: '',
    selectionID: null,
    disabled: false,
    defaultFilter: false,
    nodeData: false,
    footerMethod: null,
    formatter: {
      type: 'i18n',
      decimal: 0,
      thousandmark: false,
      currency: ''
    },
    actions: [],
    auxProp: '',
    minWidth: '',
    appWeight: '',
    isDes: false,
    many2one: {
      toTable: '_sys_fun',
      toField: 'title',
      isDropdown: false,
      customSearch: '',
      multiConnect: '',
      fields: []
    },
    align: 'left'
  }
];
const saveDetCompBind = (): any => {
  return {
    value: true, // 显示窗口
    width: '400',
    height: '300',
    type: 'confirm',
    mask: false,
    // 是否允许窗口边缘拖动调整窗口大小
    resize: true,
    // 标题是否标显示最大化与还原按钮
    showZoom: true,
    showClose: true,
    // status: '',
    title: Tsrv.getI18nByValue('保存'),
    showFooter: true,
    minWidth: 400,
    minHeiht: 300,
    // 是否允许按 Esc 键关闭窗口
    escClosable: false, // default false
    // showHeader: false,
    showTitleOverflow: true
  };
};
const oInteractionConf = (workID: string, uiID: string, formData: any) => {
  const compcf = new N_oInteraction.T_funPanel();
  compcf.group = {
    saveDet: [
      {
        form: {
          uiID,
          formColumnNum: 1,
          fields: saveDetFields()
        }
      }
    ]
  };
  compcf.initValue = {
    formData: {
      [uiID]: formData
    }
  };
  const interactionCf: N_oInteraction.I_conf = {
    cmd: N_oInteraction.V_cmd.FUN_PANEL,
    workID,
    compBind: saveDetCompBind(),
    compConf: compcf
  };
  return interactionCf;
};
const getCf = (): N_cFlowchart.I_conf => {
  const cf = new N_cFlowchart.T_conf();
  cf.regNodes = cusrNode;
  cf.regEdges = cusrEdge;
  cf.regToolbar = graphToolbar;
  cf.rightPanel = {
    show: true,
    width: 200,
    opened: false
  };
  return cf;
};
const openBpmnConfig = (): N_cFlowchart.I_conf => {
  const cf = new N_cFlowchart.T_conf();
  cf.workMode = 'view';
  return cf;
};
export {
  I_cmd,
  N_cFlowchart,
  N_oContextMenu,
  N_oInteraction,
  T_cmd,
  T_srv,
  Tsrv,
  blankContentMenuItem,
  cellContentMenuItem,
  cusrNode,
  edgeContentMenuItem,
  getCf,
  ifs,
  nodeContentMenuItem,
  oInteractionConf,
  openBpmnConfig,
  saveDetFields,
  ts,
  tvs,
  vue
};
